using System;
using System.Collections.Generic;
#if SANFORDMIDI
using Sanford.Multimedia.Midi;
#endif

namespace Kioskvalt.MidiSequencer
{
	class MidiDeviceWrapper
	{
		public bool IsOpen;
		public int ID;

		public MidiDeviceWrapper(int id)
		{
			ID = id;
			IsOpen = false;
			
#if SANFORDMIDI	
			queue = new Queue<IMidiMessage>();
			device = null;
#endif
		}

		public void Open()
		{
			Console.WriteLine("Creating a midi device wrapper for device #" + ID);
#if SANFORDMIDI
			try
			{
				device = new OutputDevice(ID);
				IsOpen = true;
			}
			catch (Exception x)
			{
				Console.WriteLine("Failed creating device: "+x.ToString());
				device = null;
			}
#endif	
		}

		public void Close()
		{
#if SANFORDMIDI
			if (device != null)
				device.Close();
			queue.Clear();
#endif
			IsOpen = false;





			
		}

#if SANFORDMIDI
		public Queue<IMidiMessage> queue;
		public OutputDevice device;
#endif
	}
     
}
